#pragma once

#include "task_handle.h"
#include "task_types.h"

#include <QDateTime>

#include <functional>
#include <memory>

namespace base::tasking {

/**
 * @brief 表示一个待执行的任务命令
 */
struct TaskCommand {
    using Ptr = std::shared_ptr<TaskCommand>;
    using WorkFunction = std::function<TaskResult(const TaskHandle::Ptr&)>;

    QString taskId;
    QString batchId;
    TaskPriority priority = TaskPriority::Normal;
    TaskCategory category = TaskCategory::Read;
    TaskRetryPolicy retryPolicy;
    int attempt = 0;
    qint64 enqueuedAt = QDateTime::currentMSecsSinceEpoch();
    TaskHandle::Ptr handle;
    WorkFunction work;

    TaskCommand() = default;

    explicit TaskCommand(WorkFunction fn)
        : work(std::move(fn))
    {}
};

/**
 * @brief 优先队列比较器
 */
struct TaskCommandComparator {
    bool operator()(const TaskCommand::Ptr& lhs, const TaskCommand::Ptr& rhs) const;

private:
    static int priorityWeight(TaskPriority priority);
};

} // namespace base::tasking
